﻿Public Partial Class Site
    Inherits System.Web.UI.MasterPage
    Public _service As New CupsApp.Service.CupsDomainService


    Public ReadOnly Property User()
        Get
            Return _service.GetCurrentUser()
        End Get
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (HttpContext.Current.User.Identity.IsAuthenticated()) Then
            lblUser.Text = String.Format("WELCOME: {0}", _service.GetCurrentUser())
            btnLogout.Visible = True
            btnChangePassword.Visible = True
            btnLogin.Visible = False
            If (HttpContext.Current.User.IsInRole("Administrator")) Then
                lnkAdmin.Enabled = True
            Else
                lnkAdmin.Enabled = False
            End If
        Else
            lnkAdmin.Enabled = False
            lblUser.Text = "Not logged in"
            btnLogout.Visible = False
            btnChangePassword.Visible = False
            btnLogin.Visible = True
        End If



    End Sub

#Region "Click Events"

    Protected Sub lnkNewClient_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkNewClient.Click
        Response.Redirect("~/Forms/personal.aspx")
    End Sub

    Protected Sub lnkNewLandlords_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkNewLandlords.Click
        Response.Redirect("~/Admin/manage_landlords.aspx")
    End Sub

    Protected Sub lnkAdmin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkAdmin.Click
        Response.Redirect("~/Admin/users.aspx")
    End Sub

    Protected Sub lnkSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkSearch.Click
        Response.Redirect("~/Forms/search.aspx")
    End Sub

    Protected Sub LnkHome_Click(ByVal sender As Object, ByVal e As EventArgs) Handles LnkHome.Click
        Response.Redirect("~/Default.aspx")
    End Sub

#End Region



    Protected Sub btnLogout_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogout.Click
        btnLogout.Visible = False
        btnChangePassword.Visible = False
        btnLogin.Visible = True
        FormsAuthentication.SignOut()
        FormsAuthentication.RedirectToLoginPage()
    End Sub

    Protected Sub btnChangePassword_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnChangePassword.Click
        Response.Redirect("~/ChangePassword.aspx")
    End Sub

    Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogin.Click
        Response.Redirect("~/Login.aspx")
    End Sub
End Class